// 获取当前时间
import { ref,reactive,onMounted,onBeforeUnmount } from 'vue'

export default function () {
    const currentDate = reactive({
        date:'',
        time:''
    })
    let timer = ref(null)
    
    const init = ()=>{
        const date = new Date()
        currentDate.date = date.toLocaleDateString()
        let hours = date.getHours()<10 ? '0'+ date.getHours() : date.getHours()
        let minutes = date.getMinutes()<10 ? '0'+date.getMinutes() : date.getMinutes()
        currentDate.time = hours+':'+minutes
    }
    init()

    onMounted(() => {
        timer = setInterval(() => {
            init()
        }, 5000);
    })

    onBeforeUnmount(()=>{
		clearInterval(timer)
	})
    

    return currentDate
}